package com.jzo2o.market.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jzo2o.market.model.domain.Coupon;
import com.jzo2o.market.model.dto.request.CouponOperationPageQueryReqDTO;
import com.jzo2o.market.model.dto.response.CouponInfoResDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author itcast
 * @since 2023-09-16
 */
@Mapper
public interface CouponMapper extends BaseMapper<Coupon> {

    @Select("select * from coupon where activity_id = #{activityId}")
    List<CouponInfoResDTO> page(CouponOperationPageQueryReqDTO pageReqDTO);

    @Update("update coupon set status = 3 where activity_id = #{id}")
    Boolean updateByActivityID(int status, Long id);

    @Select("select * from coupon where status = #{status} " +
            "and id < #{lastId} order by id desc limit 10")
    List<CouponInfoResDTO> selectByStatus(Long status, Long lastId);

    @Update("update coupon set status = #{status} where validity_time < #{now} and status=1")
    void updateByNow(int status, LocalDateTime now);
}
